package org.delphy.crimson
{
	import flash.display.GradientType;
	import flash.display.Graphics;	
	import flash.geom.Matrix;
	
	import mx.controls.TabBar;

	public class CrimsonTabBar extends TabBar
	{
		
		private var _cornerRadius:Number;

		public function get cornerRadius():Number
		{ 
			return _cornerRadius; 
		}

		public function set cornerRadius(value:Number):void
		{
			if (value !== _cornerRadius)
			{
				_cornerRadius = value;
				setStyle("cornerRadius",value);
				invalidateDisplayList();
			}
		}
		
		private var _fillColors:Array;

		public function get fillColors():Array
		{ 
			return _fillColors; 
		}

		public function set fillColors(value:Array):void
		{
			if (value !== _fillColors)
			{
				_fillColors = value;
				setStyle("fillColors",value);
				invalidateDisplayList();
			}
		}
		
		public function CrimsonTabBar()
		{
			super();

			styleName="crimsonTabBar";
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			cornerRadius=getStyle("cornerRadius");
			fillColors=getStyle("fillColors");
			
			
			var g:Graphics=graphics;
			var mat:Matrix=new Matrix();
			mat.createGradientBox(unscaledWidth,unscaledHeight,Math.PI/2);
			
			g.clear();
			g.beginGradientFill(GradientType.LINEAR,[fillColors[0],fillColors[1]],[1,1],[0,255],mat);
			g.drawRoundRect(0,0,unscaledWidth,unscaledHeight,cornerRadius,cornerRadius);
			g.endFill();
			
			// Highlight
			mat.createGradientBox(unscaledWidth-4,unscaledHeight/2,Math.PI/2);
			g.beginGradientFill(GradientType.LINEAR,[0xFFFFFF,0xFFFFFF],[0.5,0.1],[0,255],mat);
			g.drawRoundRect(2,0,unscaledWidth-4,unscaledHeight/2,cornerRadius,cornerRadius);
			g.endFill()
			
		}
		
	}
}